#include <assert.h>
#include <string.h>

#include <common/macro/build.h>
#include <common/macro/debug.h>
#include <common/util.h>
#include <query/result.h>

inline API_PUBLIC const char *result_text(result_e result) {
	const char *const texts[] = {
	/* RESULT_OK                */ "OK",
	/* RESULT_ENDOFRESULTS      */ "End of result set",

	/* RESULT_EIO               */ "Input/Output error",
	/* RESULT_ELOCK             */ "Lock error",
	/* RESULT_DEADLOCK          */ "Deadlock occured",
	/* RESULT_ETRANSACTION      */ "Transaction handling error",
	/* RESULT_PAGETYPEMM        */ "Page type versus FSM data mismatch",
	/* RESULT_PAGECORRUPT       */ "Page corrupt",
	/* RESULT_DATATOOLARGE      */ "Data too large",
	/* RESULT_INVALIDCOMMAND    */ "Invalid command issued",
	/* RESULT_CONDITIONERR      */ "Error in presented condition",
	/* RESULT_INVALIDTABLE      */ "Invalid table specified",
	/* RESULT_INVALIDCOLUMN     */ "Invalid column specified",
	/* RESULT_MISSINGDATA       */ "No data available to read or write",
	/* RESULT_TOOMANYCOMMANDS   */ "Too many UPDATE commands issued",
	};

	assert(result < (sizeof(texts) / sizeof(*texts)));

	debugmsg("Result number: %u\n", result);

	return texts[result];
}

inline API_PUBLIC int result_eod(result_e result) {
	return (result == RESULT_ENDOFRESULTS);
}

inline API_PUBLIC int result_error(result_e result) {
	return (result != RESULT_OK && result != RESULT_ENDOFRESULTS);
}

inline API_PUBLIC int result_ok(result_e result) {
	return (result == RESULT_OK);
}
